'use strict'
import * as qiniu from 'qiniu-js'

export default async function upload(file, key, token, observer) {
  let [pubExtra, config] = [
    {
      fname: file.name,
      params: {},
      mineType: null // ['image/png, image/jpeg, image/jpg, image/gif, image/bmp']
    },
    { useCdnDomain: true }
  ]

  // 图片压缩
  // var image = await qiniu.compressImage(
  //   file,
  //   {
  //     qulity: 0.9,
  //     noCompressIfLarger: true
  //   })
  var observable = qiniu.upload(file /* image.dist */, key, token, pubExtra, config)
  observable.subscribe(observer)
}
